﻿using System;

namespace Miao
{
    public class TMinMaxValue<T> : TValue<T> where T : IComparable<T>
    {
        public T MinValue { get; set; }
        public T MaxValue { get; set; }

        public TMinMaxValue(T defaultValue,T TMinValue,T MaxValue) : base(defaultValue)
        {
            this.MinValue = MinValue;
            this.MaxValue = MaxValue;

        }

        protected override void SetValue(T newValue)
        {
            if (newValue.CompareTo(MinValue) < 0)
            {
                newValue = MinValue;
            }
            else if (newValue.CompareTo(MaxValue) > 0)
            {
                newValue = MaxValue;
            }
            base.SetValue(newValue);

        }
    }
}
